<?php
/**
 * Created by PhpStorm.
 * User: 技术员专用
 * Date: 2019/2/18
 * Time: 14:29
 */

namespace app\admin\controller;

use GuzzleHttp\Client;
class Tuling
{
    private $client;

    public function __construct($options)
    {
        $this->client  = new Client();
        $this->options =$options;
    }

    public function search($text)
    {
        $client = new Client();
        $res    = $client->request('POST', $this->options['tulingApi'],
            ['body' => json_encode(
                [
                    'key'   => $this->options['tulingKey'],
                    'info'  => $text,
                ]
            )]);
        $res    =$res->getBody()->getContents();
        $content=json_decode($res, true);
        $url    =isset($content['url']) ? ' ' . $content['url'] : '';

        return $content['text'] . $url;
    }
}